package com.nq.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nq.common.Result;
import com.nq.stock.entity.StIpo;
import com.nq.stock.service.IStIpoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;

/**
* @Description: st_ipo
* @Author: jeecg-boot
* @Date:   2024-06-05
* @Version: V1.0
*/
@RestController
@RequestMapping("/api/stIpo")
@Slf4j
public class ApiIpoController {
   @Autowired
   private IStIpoService stIpoService;

   /**
    * 分页列表查询
    *
    * @param stIpo
    * @param pageNo
    * @param pageSize
    * @param req
    * @return
    */
   @GetMapping(value = "/list")
   public Result<?> queryPageList(StIpo stIpo,
                                  @RequestParam(value = "changePercent", required = false) String changePercent,
                                  @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                  @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
                                  HttpServletRequest req) {
       QueryWrapper<StIpo> queryWrapper = new QueryWrapper<>();
       queryWrapper.orderByDesc("create_time");

       Page<StIpo> page = new Page<StIpo>(pageNo, pageSize);
       IPage<StIpo> pageList = stIpoService.page(page, queryWrapper);
       return Result.OK(pageList);
   }

   /**
    *   添加
    *
    * @param stIpo
    * @return
    */
   @PostMapping(value = "/add")
   public Result<?> add(@RequestBody StIpo stIpo) {
       stIpoService.save(stIpo);
       return Result.OK("Added successfully！");
   }

   /**
    *  编辑
    *
    * @param stIpo
    * @return
    */
   @PutMapping(value = "/edit")
   public Result<?> edit(@RequestBody StIpo stIpo) {
       stIpoService.updateById(stIpo);
       return Result.OK("Editing successfully!");
   }

   /**
    *   通过id删除
    *
    * @param id
    * @return
    */
   @DeleteMapping(value = "/delete")
   public Result<?> delete(@RequestParam(name="id",required=true) String id) {
       stIpoService.removeById(id);
       return Result.OK("Deleted successfully!");
   }

   /**
    *  批量删除
    *
    * @param ids
    * @return
    */
   @DeleteMapping(value = "/deleteBatch")
   public Result<?> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
       this.stIpoService.removeByIds(Arrays.asList(ids.split(",")));
       return Result.OK("Batch Delete Successfully!");
   }

   /**
    * 通过id查询
    *
    * @param id
    * @return
    */
   @GetMapping(value = "/queryById")
   public Result<?> queryById(@RequestParam(name="id",required=true) String id) {
       StIpo stIpo = stIpoService.getById(id);
       if(stIpo==null) {
           return Result.error("No corresponding data found!");
       }
       return Result.OK(stIpo);
   }
//
//    /**
//    * 导出excel
//    *
//    * @param request
//    * @param stIpo
//    */
//    @RequestMapping(value = "/exportXls")
//    public ModelAndView exportXls(HttpServletRequest request, StIpo stIpo) {
//        return super.exportXls(request, stIpo, StIpo.class, "st_ipo");
//    }
//
//    /**
//      * 通过excel导入数据
//    *
//    * @param request
//    * @param response
//    * @return
//    */
//    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
//    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
//        return super.importExcel(request, response, StIpo.class);
//    }

}
